package com.ccl.dao;

import com.ccl.entity.Statistic;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface StatisticMapper {
    //查询排行榜信息
    @Select("select * from t_statistic order by hits desc limit 10")
    public List<Statistic> findHeadData();

    //根据id更新文章点击量+1
    @Update("update t_statistic set hits=hits+1 where article_id=#{articleId}")
    public void updateHits(Integer articleId);

    //根据id更新文章评论量+1
    @Update("update t_statistic set comments_num=comments_num +1 where article_id=#{articleId}")
    public void updateCommentNum(Integer articleId);

    //根据文章id查询Statistic对象
    @Select("select * from t_statistic where article_id=#{articleId}")
    public Statistic findByArticleId(Integer articleId);

    //添加statistic(统计新文章)
    @Insert("insert into t_statistic(article_id,hits,comments_num) " +
            "values(#{articleId},#{hits},#{commentsNum})")
    public  void addStatistic(Statistic statistic);
    //根据id删除文章
    @Delete("delete  from t_statistic where article_id=#{articleId}")
    public void deleteByArticleId(Integer articleId);

    //更新统计表:Statistic对象
    public void updateStatistic(Statistic statistic);

    //统计总点击量
    @Select("select sum(hits) from t_statistic")
    public int getHitsNum();

}
